#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char const *argv[])
{
    if ( argc != 3)
    {
        printf("Pls input: ./a.out <dst file name> <string to write>\n");
        return -1;
    }

    int fdFileDst = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0664);
    if ( -1 == fdFileDst )
    {
        perror("fail open");
        return -1;
    } 
    printf("file descriptor of <%s> is %d\n", argv[1], fdFileDst);

    ssize_t szReturn;
    szReturn = write( fdFileDst, argv[2], strlen(argv[2]));
    if ( szReturn == -1)
    {
        perror("fail write");
        return -1;
    }
    printf("Write %ld bytes to <%s>\n", szReturn, argv[1]);

    int iNumWrite = 8;
    szReturn = write( fdFileDst, &iNumWrite, sizeof(iNumWrite) );
    if ( szReturn == -1)
    {
        perror("fail write");
        return -1;
    }
    printf("Write %ld bytes to <%s>\n", szReturn, argv[1]);   

    close(fdFileDst);
  
    return 0;
}

/********************************************

系统调用函数 open write close
shell传参给main函数
判断每一个会设置 errno 的函数返回值

********************************************/
